package kr.co.doriclassic.mypuppystory.alarmpuppy;

import android.annotation.SuppressLint;

import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;

@SuppressLint("SimpleDateFormat")
public class ChangeFormat {
	private static SimpleDateFormat df;
	private static final String pattern = "yyyy-MM-dd";

	public long stringToLong(String sDate) throws ParseException {
		df = new SimpleDateFormat(pattern);
		long date = ((df.parse(sDate)).getTime()) / (1000 * 60 * 60 * 24);
		return date;
	}

	public String longToString(long lDate) {
		SimpleDateFormat formatter = new SimpleDateFormat(pattern);
		String date = (String) formatter.format(new Timestamp(lDate));
		return date;
	}

	public String dateToString(int mYear, int mMonth, int mDay)
	{
		StringBuilder sb = new StringBuilder();
		// 월은 시스템에서 0~11로 인식하기 때문에
		// 1을 더해줌
		sb.append(mYear)
		.append("-");
		
		if((mMonth+1)<10)
			sb.append("0"+ (mMonth + 1));
		else
			sb.append(mMonth + 1);
		
		sb.append("-");
		
		if(mDay<10)
			sb.append("0"+ mDay);
		else
			sb.append(mDay);
		
		
		return sb.toString();
	}
}
